package com.erp.module.zhuanMaiDianTu

import android.content.Context
import com.erp.bean.ZhuanMaiDianBean
import com.erp.Interface.OnUserDataInterface
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

/**
 * Created by Administrator on 2019/3/20/020.
 * 作者：刘洋
 */
class IZhuanMaiDianP(var V: ZhuanMaiDianTuContract.ZhuanMaiDianView, var  context : Context, var list :MutableList<ZhuanMaiDianBean>):BasePullP(),ZhuanMaiDianTuContract.ZhuanMaiDianP {
    var md =ZhuanMaiDianTuModel()
    var sousuocode =0
    var sousuo = ""
    init {
        PullV =V
    }
    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        md.getZhuanMaiDian(context, page, pagesize, sousuocode, sousuo,onUserDataInterface)
    }

    override fun jsondata(data: String?) {
        if(data==null){
            return
        }
        try {
            val js = JSONArray(data)
            for (i in -0 until js.length()) {
                val bean = ZhuanMaiDianBean()
                val jo = js.get(i) as JSONObject
                bean.uid = JsonUtil.getvolue(jo, "uid")
                bean.name = JsonUtil.getvolue(jo, "name")
                bean.id_num = JsonUtil.getvolue(jo, "id_num")
                bean.alias_name = JsonUtil.getvolue(jo, "alias_name")
                bean.area_name = JsonUtil.getvolue(jo, "area_name")
                bean.province = JsonUtil.getvolue(jo, "province")
                bean.status = JsonUtil.getvolue(jo, "status")
                bean.withdraw_es = JsonUtil.getvolue(jo, "withdraw_es")
                bean.join_time = JsonUtil.getvolue(jo, "join_time")
                bean.expire_time = JsonUtil.getvolue(jo, "expire_time")
                bean.created = JsonUtil.getvolue(jo, "created")
                bean.ctime = JsonUtil.getvolue(jo, "ctime")
                list.add(bean)
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }

    override fun listClean() {
        list.clear()
    }

    override fun chaxun(sousuocode: Int, sousuo: String) {
        this.sousuocode=sousuocode
        this.sousuo=sousuo
        xiala()
    }
}